package org.qiyu.live.im.core.server.common;

import io.netty.channel.ChannelHandlerContext;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description: 我们这里使用一个Map来进行管理已经建立的连接
 * User: sfx
 * Date: 2023-10-09
 * Time: 16:49
 */
public class ChannelHandlerContextCache {
    private static final Map<Long, ChannelHandlerContext> channelHandlerContextMap = new HashMap<>();

    private static String IM_CORE_SERVER_ADDRESS;

    public static String getImCoreServerAddress() {
        return IM_CORE_SERVER_ADDRESS;
    }

    public static void setImCoreServerAddress(String imCoreServerAddress) {
        IM_CORE_SERVER_ADDRESS = imCoreServerAddress;
    }

    // 接下来,我们封装一下 get, put, remove 操作
    public static void put(Long userId, ChannelHandlerContext channelHandlerContext) {
        channelHandlerContextMap.put(userId, channelHandlerContext);
    }

    public static ChannelHandlerContext get(Long userId) {
        return channelHandlerContextMap.get(userId);
    }

    public static void remove(Long userId) {
        channelHandlerContextMap.remove(userId);
    }
}